package collection.set;

import java.text.Collator;
import java.util.Collections;
import java.util.Locale;
import java.util.TreeSet;

public class Test2 {
    public static void main(String[] args) {
        TreeSet<Role> roles = new TreeSet<>();
        Collections.addAll(roles,
                new Role("灭霸",10086,9999),
                new Role("虚鲲", 8888, 912),
                new Role("张虚鲲", 8888, 912),
                new Role("李虚鲲", 8888, 912),
                new Role("肌肉金轮", 777,6666),
                new Role("巴黎剩母", 777,6666),
                new Role("野兽前辈",23,114514),
                new Role("卢本伟", 1000,6666),
                new Role("PDD",96,888));
        System.out.println(roles);
    }
}

class Role implements Comparable<Role> {

    private String name;
    private int age;
    private int attract;


    public Role() {
    }

    public Role(String name, int age, int attract) {
        this.name = name;
        this.age = age;
        this.attract = attract;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     * @return attract
     */
    public int getAttract() {
        return attract;
    }

    /**
     * 设置
     * @param attract
     */
    public void setAttract(int attract) {
        this.attract = attract;
    }

    public String toString() {
        return "姓名：" + name + ", age = " + age + ", attract = " + attract + "}";
    }

    @Override
    public int compareTo(Role o) {
        int result = o.attract - this.attract;
        result = result == 0 ? this.age - o.age : result;
        result = result == 0 ? this.getName().length() - o.getName().length() : result;
        Collator compare = Collator.getInstance(Locale.CHINA);
        result = result == 0 ? compare.compare(this.getName(), o.getName()) : result;
//        result = result == 0 ? this.name.compareTo(o.name) : result;
        return result;
    }
}
